<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 500px;
        margin: 100px auto;
      }
      img {
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="btns">
        <input type="button" value="第一张" />
        <input type="button" value="第二张" />
        <input type="button" value="第三张" />
        <input type="button" value="第四张" />
        <input type="button" value="第五张" />
      </div>
      <div>
        <img id="img" src="./images/01-01.jpg" alt="" />
      </div>
    </div>
    <script>
      var img = document.getElementById('img')
      var btns = document.getElementsByTagName('input')
      var imgs = ['./images/01-01.jpg', './images/01-02.jpg', './images/01-03.jpg', './images/01-04.jpg', './images/01-05.jpg']
      for (var i = 0; i < btns.length; i++) {
        btns[i].index = i
        btns[i].onclick = function () {
          img.src = imgs[this.index]
        }
      }
    </script>
  </body>
</html>
